package main

import (
	"github.com/tealeg/xlsx"
	"log"
)

func main() {
	excel := xlsx.NewFile()

	// 新建一个sheet
	sheet, err := excel.AddSheet("Sheet1")
	if err != nil {
		log.Fatal(err)
	}

	// 创建首行
	headerRow := sheet.AddRow()

	// 设置行高
	headerRow.SetHeightCM(0.5)

	// 填充行中的单元格
	headerRow.AddCell().Value = "姓名"
	headerRow.AddCell().Value = "年龄"

	valList := [][]string{
		{"张三", "13"},
		{"李四", "14"},
		{"王五", "15"},
	}

	for _, line := range valList {
		row := sheet.AddRow()
		row.SetHeightCM(0.5)
		for _, v := range line {
			row.AddCell().Value = v
		}
	}

	// 持久化到磁盘
	if err := excel.Save("username.xlsx"); err != nil {
		log.Fatal(err)
	}

	test()
}

type Username struct {
	Name string
	Age uint8
}

func test()  {
	var data = []Username{
		{
			Name: "张三",
			Age:  13,
		},
		{
			Name: "李四",
			Age:  14,
		},
		{
			Name: "王五",
			Age:  15,
		},
	}
	excel, err := Struct2Xlsx(data)
	if err != nil {
		panic(err)
	}
	if err := excel.Save("username.xlsx"); err != nil {
		panic(err)
	}
}

func Struct2Xlsx(data []Username) (interface{}, interface{}) {
	
}

}